import { UserProfilesAPI } from "../../request/api";
export default {
  namespaced: true,
  state: {
    //用户信息
    userInfo: {
      nickName: "niCheng",
      coin: "jituoshu ",
      headImg: require("../../assets/img/service.848ec511.png"),
    },
    //   购物车总数
    cartTotal: 99,
  },
  mutations: {
    //修改是否显示模态框的数据
    changeUserInfo(state, payload) {
      state.userInfo = payload.userInfo;
      state.cartTotal = payload.cartTotal;
    },
    //   初始化信息
    initUserInfo(state) {
      state.userInfo = {
        nickName: "niCheng",
        coin: "jituoshu ",
        headImg: require("../../assets/img/service.848ec511.png"),
      };
    },
  },
  actions: {
    async asyncChangeUserInfo({ commit }, payload) {
      let user = await UserProfilesAPI();
      console.log("asyncChangeUserInfo", user);
      //   /调用mutations 的方法
      commit("changeUserInfo", user.data);
    },
  },
};
